/**
 * 公证点管理js
 */

$(function () {
    initialPage();
    getGrid();
});

function initialPage() {
    $(window).resize(function() {
        $('#dataGrid').bootstrapTable('resetView', {height: $(window).height()-54});
    });
}

function getGrid() {
    $('#dataGrid').bootstrapTableEx({
        url: '../../sys/node/list?_' + $.now(),
        height: $(window).height()-54,
        clickToSelect:false,
        queryParams: function(params){
            params.keyword = vm.keyword;
            return params;
        },
        columns: [{
            checkbox: true
        }, {
            field : "nodeName",
            title : "公证点名称",
            width : "200px",
        },  {
            field : "nodeLocation",
            title : "公证点位置",
            width : "300px"
        },{
            field : "nodePhnoe",
            title : "门店电话",
            width : "130px"
        },{
            field : "nodeMajor",
            title : "联系人",
            width : "130px"
        },  {
            field : "nodeMajorPhone",
            title : "联系人电话",
            width : "130px"
        }, {
            field : "status",
            title : "状态",
            width : "60px",
            formatter : function(value , row, index) {
                if(value=='0'){
                    return '<span class="label label-danger">禁用</span>';
                }else if(value=='1'){
                    return '<span class="label label-success">正常</span>';
                }
            }
        },{
            field : "create_date",
            title : "创建时间"
        }]
    })
}

var vm = new Vue({
    el:'#dpLTE',
    data: {
        keyword: null
    },
    methods : {
        load: function() {
            $('#dataGrid').bootstrapTable('refresh');
        },
        save: function() {
            dialogOpen({
                title: '新增公证点',
                url: 'base/node/add.html?_' + $.now(),
                width: '600px',
                height: '350px',
                scroll : true,
                yes : function(iframeId) {
                    top.frames[iframeId].vm.acceptClick();
                },
            });
        },
        edit: function() {
            var ck = $('#dataGrid').bootstrapTable('getSelections');
            if(checkedRow(ck)){
                dialogOpen({
                    title: '编辑公证点',
                    url: 'base/node/edit.html?_' + $.now(),
                    width: '600px',
                    height: '350px',
                    scroll : true,
                    success: function(iframeId){
                        top.frames[iframeId].vm.user.userId = ck[0].userId;
                        top.frames[iframeId].vm.setForm();
                    },
                    yes : function(iframeId) {
                        top.frames[iframeId].vm.acceptClick();
                    },
                });
            }
        },
        remove: function() {
            var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];
            if(checkedArray(ck)){
                $.each(ck, function(idx, item){
                    ids[idx] = item.nodeId;
                });
                $.RemoveForm({
                    url: '../../sys/node/remove?_' + $.now(),
                    param: ids,
                    success: function(data) {
                        vm.load();
                    }
                });
            }
        },
        disable: function() {
            var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];
            if(checkedArray(ck)){
                $.each(ck, function(idx, item){
                    ids[idx] = item.nodeId;
                });
                $.ConfirmForm({
                    msg: '您是否要禁用所选公证点吗？',
                    url: '../../sys/node/disable?_' + $.now(),
                    param: ids,
                    success: function(data) {
                        vm.load();
                    }
                });
            }
        },
        enable: function() {
            var ck = $('#dataGrid').bootstrapTable('getSelections'), ids = [];
            if(checkedArray(ck)){
                $.each(ck, function(idx, item){
                    ids[idx] = item.nodeId;
                });
                $.ConfirmForm({
                    msg: '您是否要启用所选公证点吗？',
                    url: '../../sys/node/enable?_' + $.now(),
                    param: ids,
                    success: function(data) {
                        vm.load();
                    }
                });
            }
        },
    }
})